﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;

namespace ASPItalia.ModelVirtualCasting.Web.Utils
{
    public class ForbiddenValuesConstraint : IRouteConstraint
    {
        private List<string> forbiddenValues;

        public ForbiddenValuesConstraint(params string[] forbiddenValues)
        {
            this.forbiddenValues = new List<string>(forbiddenValues);
        }

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            return !this.forbiddenValues.Contains<string>(
                (string)values[parameterName], StringComparer.InvariantCultureIgnoreCase);
        }
    }
}